package com.xzq.erp.ai.tools;

import com.xzq.erp.context.BaseContext;
import com.xzq.erp.domain.dto.PageDTO;
import com.xzq.erp.domain.query.OrderPageQuery;
import com.xzq.erp.domain.vo.OrderVO;
import com.xzq.erp.enums.ResponseCodeEnum;
import com.xzq.erp.exception.BizException;
import com.xzq.erp.service.IOrderService;
import com.xzq.erp.service.ISysRolePermissionService;
import com.xzq.erp.utils.Response;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import java.util.List;
import java.util.Objects;

@Component
@RequiredArgsConstructor
public class RoleAndPermissionTools {

    private final ISysRolePermissionService sysRolePermissionService;


    // 同一个chat请求调用多个工具，对应工具都要获取ToolContext
    @Tool(name="查询用户角色和权限",description = "查询当前登录用户角色和权限,不要返回权限字符例如:role:list")
    public List<String> getUserPermissions(ToolContext toolContext) {
        Long userId = (Long) toolContext.getContext().get("userId");
        if (Objects.isNull(userId)) {
            throw new BizException(ResponseCodeEnum.UNAUTHORIZED);
        }
        // 设置当前用户ID
        BaseContext.setUserId(userId);
        return sysRolePermissionService.getUserPermissions();
    }
}
